package gui.arp;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JLabel;

public class ArpCellEditorMouseAdapter extends MouseAdapter {
	private int lastPos;
	
	public ArpCellEditorMouseAdapter() {
		super();
		lastPos = 0;
	}
	
	@Override
	public void mouseReleased(MouseEvent e) {
		System.out.println("Click!");
	}
	
	@Override
	public void mouseDragged(MouseEvent e) {
		JLabel lblTune = (JLabel) e.getSource();
		int value = Integer.parseInt(lblTune.getText());
		if (value > -37 && value < 37) {
			int y = e.getY();
			int newVal = value + (lastPos - y) / 2;
			if (newVal > 36) newVal = 36;
			if (newVal < -36) newVal = -36;
			lblTune.setText("" + newVal);
			lastPos = y;
		}
	}
	
	public void resetLastPos() {
		lastPos = 0;
	}
}
